define(['app'], function(app) {
	'use strict';

	// 实例化方法
	var factory = function(Http) {
		//新品广告活动的详细
		function get_data_detail(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"act_id": "act_id_005","name": "圣诞促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","brand_id": "001","cat_type": [{"id": "001"},{"id": "002"},{"id": "003"}],"goods": [{"goods_id": "001","name": "一字螺丝刀1","video_id": "001","video": ""},{"goods_id": "002","name": "十字螺丝刀2","video_id": "001","video": ""}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};
		//编辑
		function get_data_edit(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"act_id":"001"},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};
		//品牌
		function get_data_brandList(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"brand": ['+
				'{"id": "001","name": "世达"},'+
				'{"id": "002","name": "博士"}'+
        	']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};
		//商品选择
		function get_data_goodsList(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"store_count":"500","data":[{"goods_id":1,"name":"十字螺丝刀","introduce":"十字螺丝刀","price":5.5,"mktprice":8,"preprice":5.5,"store_id":"WuJin_1","store_name":"五金一店","image":"LuoSiDao_ShiZi,jpg","storenumber":100,"salenumber":20,"personlimit":3,"qq":"1234567","phone":"18912345678"},{"goods_id":2,"name":"一字螺丝刀","introduce":"一字螺丝刀","price":5.5,"mktprice":8,"preprice":5.5,"store_id":"WuJin_1","store_name":"五金一店","image":"LuoSiDao_YiZi,jpg","storenumber":80,"salenumber":10,"personlimit":3,"qq":"1234567","phone":"18912345678"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		// 返回信息
		return {
			//新品广告活动的详细
			detail: function(act_id, callback) {
				Http.post({
					method: 'marketing.video.detail',
					session:'',
					act_id:act_id
				}, function(result) {
					if(callback)
						callback(get_data_detail(result).result);
				}, function(e) {

				}, function() {

				});
			},
			//编辑
			edit: function(act_id,name,start_time,end_time,brand_id,cat_types,goods,callback) {
				Http.post({
					method : 'marketing.video.createedit',
					updateParams:{
    					  act_id:act_id,
    					  name:name,
    					  start_time:start_time,
    					  end_time:end_time,
    					  brand_id:brand_id,
    					  cat_type:cat_types,
    					  goods:goods
					}
				}, function(result) {
					// 请求成功
					if (callback)
						callback(get_data_edit(result));
				}, function(e) {
					// 请求异常
				}, function() {
					// 请求完成，一般不做什么事情
				});
			},
			//品牌
			brandList: function(callback) {
				Http.post({
						method: 'goods.brand.getlist',
						session:''
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_brandList(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			},
			//选择商品
			goodsList: function(cat_type, callback) {
				Http.post({
						method: 'goods.search.getlist',
						session:'',
						cat_type:cat_type
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_goodsList(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			}


		};
	}

	factory.$inject = [ 'Http' ];
	return app.registerService("Ads", factory);
});